<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>公告通知管理</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="notice"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>公告通知管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/notice/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">

                        <div class="form-group">
                            <label>创建日期查询：</label>
                            <input placeholder="请输入开始日期" type="text" class="form-control input-date"
                                   name="minCreateDate" value="${(qo.minCreateDate?string("yyyy-MM-dd"))!}"/> -
                            <input placeholder="请输入结束日期" type="text" class="form-control input-date"
                                   name="maxCreateDate" value="${(qo.maxCreateDate?string("yyyy-MM-dd"))!}"/>
                        </div>

                        <div class="form-group">
                            <label>公告级别：</label>
                            <select class="form-control" name="grade">
                                <option value="">请选择级别</option>
                                <#list enums as e>
                                    <option value="${e.getValue()}">${e.getName()}</option>
                                </#list>
                                <script>
                                    $('select[name=grade]').val(${qo.grade})
                                </script>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>阅读状态：</label>
                            <select class="form-control" name="isRead">
                                <option value="">全部</option>
                                <option value="0">未读</option>
                                <option value="1">已读</option>
                            </select>
                            <script>
                                $('select[name=isRead]').val(${(qo.isRead?string('1','0'))!})
                            </script>
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <#if admin== true>
                            <a href="#" class="btn btn-success btn-input">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </#if>
                    </form>
                </div>
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>公告标题</th>
                            <th>创建人</th>
                            <th>创建时间</th>
                            <th>公告级别</th>
                            <th>是否已读</th>
                            <#if admin== true>
                                <th>发布状态</th>
                                <th>已读人数</th>
                            </#if>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as n >
                            <tr>
                                <td>${n_index + 1}</td>
                                <td>${n.title}</td>
                                <td>${n.employee.name}</td>
                                <td>${(n.createTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                                <td>${n.findName()}</td>
                                <td>${(n.isRead?string('已读','未读'))!}</td>
                                <#if admin== true>
                                    <td>${(n.status?string('已发布','未发布'))!}</td>
                                    <td>已读${n.readNotice.read}人 未读${n.readNotice.noRead}人</td>
                                </#if>
                                <td>
                                    <a class="btn btn-success btn-xs  btn-show" data-json='${n.toJSON()}'>
                                        <span class="glyphicon glyphicon-phone-alt"></span> 查看</a>
                                    <#if admin== true>
                                        <a class="btn btn-primary btn-xs btn-input" data-json='${n.toJSON()}'>
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                        <a class="btn btn-xs btn-info btn-push glyphicon-status"
                                           data-status='${n.status}' data-id='${n.id}'>
                                            <span class="glyphicon glyphicon-share "></span> 发布</a>
                                        <a class="btn btn-xs btn-danger btn-remove glyphicon-status"
                                           data-status='${n.status}' data-id='${n.id}'>
                                            <span class="glyphicon glyphicon-remove "></span> 取消</a>
                                    </#if>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                    <#include "/common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/notice/saveOrUpdate" method="post">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告标题：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" placeholder="请输入公告标题" name="title"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告内容：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control" rows="8"
                                      placeholder="请输入公告内容" name="content"></textarea>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告级别：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="grade">
                                <option value="">请选择级别</option>
                                <#list enums as e>
                                    <option value="${e.getValue()}">${e.getName()}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $('.btn-show').click(function () {
        let json = $(this).data('json');
        let id = json.id;
        window.location.href = '/notice/show?id=' + id;
    });

    $('.glyphicon-status').click(function () {
        let id = $(this).data('id');
        let status = $(this).data('status');
        $.get('/notice/updateStatus', {id: id, status: status}, function (data) {
            if (data.success) {
                //弹框表示加载成功,当用户点击确定,重新刷新页面
                Swal.fire({
                    text: "操作成功",
                    icon: 'success',
                    confirmButtonText: 'ok',
                }).then((result) => {
                    if (result.value) {
                        window.location.reload();
                    }
                })
                //如果加载失败
            } else {
                Swal.fire(
                    data.msg,
                    '',
                    'error',
                )
            }
        })
    });

    $(".btn-input").click(function () {
        let json = $(this).data('json');
        $('#editForm input , textarea , select').val('');
        if (json) {
            $('#editForm input[name=id]').val(json.id);
            $('#editForm input[name=title]').val(json.title);
            $('#editForm textarea[name=content]').val(json.content);
            $('#editForm select[name=grade]').val(json.grade);
        }
        $("#editModal").modal('show')
    });

    $("#editForm").ajaxForm(function (data) {
        if (data.success) {
            //弹框表示加载成功,当用户点击确定,重新刷新页面
            Swal.fire({
                text: "操作成功",
                icon: 'success',
                confirmButtonText: 'ok',
            }).then((result) => {
                if (result.value) {
                    window.location.reload();
                }
            })
            //如果加载失败
        } else {
            Swal.fire(
                data.msg,
                '',
                'error',
            )
        }
    });


    //其他账号有多少条未读
    $.get('/notice/unreadSum', function (data) {


    })
</script>

</body>
</html>
